﻿
using System;
using System.Text;
using System.Data;
using System.Data.Common;
using System.Collections.Generic;
using Microsoft.Practices.EnterpriseLibrary.Data;
using Microsoft.Practices.EnterpriseLibrary.Data.Sql;
using BE;

namespace DA
{
    public class daPozo
    {
        public static DataTable Obtener(bePozo oBE)
        {
            SqlDatabase sqlClient = new SqlDatabase(Configuracion.GetConnection);
            DbCommand dbCmd = sqlClient.GetStoredProcCommand("sp_ConsultarPozo");
            sqlClient.AddInParameter(dbCmd, "@IDPozo", DbType.Int32, oBE.IDPozo);
            sqlClient.AddInParameter(dbCmd, "@IDServicioPerforacion", DbType.Int32, oBE.IDServicioPerforacion);
            sqlClient.AddInParameter(dbCmd, "@IDMaquinaria", DbType.Int32, oBE.IDMaquinaria);
            sqlClient.AddInParameter(dbCmd, "@Metraje", DbType.String, oBE.Metraje);
            sqlClient.AddInParameter(dbCmd, "@Coordenadas", DbType.String, oBE.Coordenadas);
            sqlClient.AddInParameter(dbCmd, "@Ubicacion", DbType.String, oBE.Ubicacion);
            sqlClient.AddInParameter(dbCmd, "@Observaciones", DbType.String, oBE.Observaciones);
            return sqlClient.ExecuteDataSet(dbCmd).Tables[0];
        }

        public static Int32 Registrar(bePozo oBE)
        {
            SqlDatabase sqlClient = new SqlDatabase(Configuracion.GetConnection);
            DbCommand dbCmd = sqlClient.GetStoredProcCommand("sp_RegistrarPozo");
            sqlClient.AddInParameter(dbCmd, "@IDPozo", DbType.Int32, oBE.IDPozo);
            sqlClient.AddInParameter(dbCmd, "@IDServicioPerforacion", DbType.Int32, oBE.IDServicioPerforacion);
            sqlClient.AddInParameter(dbCmd, "@IDMaquinaria", DbType.Int32, oBE.IDMaquinaria);
            sqlClient.AddInParameter(dbCmd, "@Metraje", DbType.String, oBE.Metraje);
            sqlClient.AddInParameter(dbCmd, "@Coordenadas", DbType.String, oBE.Coordenadas);
            sqlClient.AddInParameter(dbCmd, "@Ubicacion", DbType.String, oBE.Ubicacion);
            sqlClient.AddInParameter(dbCmd, "@Observaciones", DbType.String, oBE.Observaciones); 
            return Convert.ToInt32(sqlClient.ExecuteScalar(dbCmd));
        }

        public static Int32 Eliminar(bePozo oBE)
        {
            SqlDatabase sqlClient = new SqlDatabase(Configuracion.GetConnection);
            DbCommand dbCmd = sqlClient.GetStoredProcCommand("sp_EliminarPozo");
            sqlClient.AddInParameter(dbCmd, "@IDPozo", DbType.Int32, oBE.IDPozo);

            return Convert.ToInt32(sqlClient.ExecuteScalar(dbCmd));
            //sqlClient.ExecuteNonQuery(dbCmd);
        }
    }
}
